package com.kreedx.duitang.scrapy;

import com.geccocrawler.gecco.annotation.*;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.spider.JsonBean;
import com.geccocrawler.gecco.spider.SpiderBean;
import lombok.Data;

@Data
@Gecco(matchUrl = {"https://www.duitang.com/blog/?id={id}"}, pipelines = "imgPipeline")
public class ImgWrapper implements SpiderBean {
    @Request
    HttpRequest request;

    @HtmlField(cssPath = "h1")
    private String title;

    @RequestParameter("id")
    private Integer blogId;

    @Image(download = "img")
//    @Attr("src")
    @HtmlField(cssPath = "#mbpho-img")
    private String img;

    // TODO 图片在不同图集下 可能会跑错图集
//    @Href(click = true)
    @HtmlField(cssPath = "#pgdetail > div.de-img > a.shownext")
    private String next;

    @Ajax(url ="https://www.duitang.com/napi/blog/detail/?blog_id={id}&include_fields=tags,related_albums,related_albums.covers,root_album,share_links_2,extra_links,icon_description,root_id")
    private Detail detail;

    @Data
    public static class Detail implements JsonBean{
        @JSONPath("$.data.next_id")
        private Integer next;
    }
}
